﻿using BSChuangXu.API.Read.Appicant.Commend.RoleCommend;
using BSChuangXu.API.Read.Appicant.Commend.UserCommand;
using BSChuangXu.API.Read.DTO;
using BSChuangXu.Domain.User;
using BSChuangXu.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace BSChuangXu.API.Read.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<UserModel>> Login([FromQuery]LoginCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<UserDto>>> GetUser([FromQuery] GetUserCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 用户名唯一
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<object>> OneUserName([FromQuery]OnenessUserNameCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 部门id查询名称
        /// </summary>
        /// <param name="requset"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserModel>>> GetDepUserName([FromQuery]GetDepIdUserCommend requset)
        {
            return mediator.Send(requset);
        }
        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RoleModel>>> GetRole([FromQuery]GetRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 角色反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<RoleModel>> RoleFanTian([FromQuery]RoleFanTianCommand request)
        {
            return mediator.Send(request) ;
        }
        /// <summary>
        /// 根据部门Id查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserModel>>> GetUserName([FromQuery] GetDepIdUserCommend request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 通过角色ID查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserNameDTOs>>> GetUserNameRoleId([FromQuery] GetUserNameRoleidCommand request)
        {
            return mediator.Send(request);
        }
    }
}
